<html>
<head><meta charset="utf-8"><title>valid constants · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/valid.20constants.html">valid constants</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="159538137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/valid%20constants/near/159538137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/valid.20constants.html#159538137">(Feb 27 2019 at 18:13)</a>:</h4>
<p>Hi everyone, I'd like to know what mechanism the compiler uses to decide which expressions are valid constants or valid inside a constant function</p>



<a name="159586305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/valid%20constants/near/159586305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/valid.20constants.html#159586305">(Feb 28 2019 at 07:56)</a>:</h4>
<p>There's currently two things, <code>librustc_mir/transform/const_qualif.rs</code> for constants and unstable const fn. Then there's <code>librustc_mir/transform/qualif_min_const_fn.rs</code></p>



<a name="159586322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/valid%20constants/near/159586322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/valid.20constants.html#159586322">(Feb 28 2019 at 07:57)</a>:</h4>
<p>The latter is for stable const fn</p>



<a name="159621949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/valid%20constants/near/159621949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/valid.20constants.html#159621949">(Feb 28 2019 at 15:12)</a>:</h4>
<p>thank you, I'm not familiarized with the structures shown in <code>qualify_consts.rs</code>, i can understand parts of it but not the whole picture. I suppose that at the end something qualify as a constant if is a part of a constant, is the result of a <code>const fn</code> or is the result of operating constants  (excluding  raw pointer operations), am I missing something?</p>



<a name="159626432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/valid%20constants/near/159626432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/valid.20constants.html#159626432">(Feb 28 2019 at 15:59)</a>:</h4>
<p>Well, there are some details like the differences between statics and constants wrt what is permitted and how promotion has special rules. Also we don't allow <code>box</code> keywords, but yes, most things boil down to safe primitives or const fn calls</p>



<a name="159627400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/valid%20constants/near/159627400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/valid.20constants.html#159627400">(Feb 28 2019 at 16:09)</a>:</h4>
<p>ok then, thank you Oliver!</p>



<a name="159629484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/valid%20constants/near/159629484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/valid.20constants.html#159629484">(Feb 28 2019 at 16:33)</a>:</h4>
<p>Well, there are some details like the differences between statics and constants wrt what is permitted and how promotion has special rules. Also we don't allow <code>box</code> keywords, but yes, most things boil down to safe primitives or const fn calls</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>